The present invention relates to the field of electronic devices, and, more particularly, to microprocessors that may be switched to perform a test program. The present invention also relates to a method of managing the memory space of a microprocessor after switching the microprocessor to perform a test program, and the recording of contextual data into a stack.
It is conventional to provide, in the memory of a microprocessor, a test program which allows control of the microprocessor to be taken over by external equipment (e.g., a test station) to check the operation of the microprocessor and/or debug an application program. To aid in further understanding, FIG. 1 schematically shows a microprocessor MP1 including a central processing unit CPU, a non-volatile program memory PMEM, a test memory TMEM, and a volatile memory RMEM. The memories PMEM, TMEM and RMEM are, for example, FLASH-, ROM- and RAM-type memories, respectively.
Memory TMEM receives a test program TST-PGR provided by the manufacturer, and memory PMEM receives an application program APL-PGR developed by the user. The RAM memory, provided for storing temporary data, receives the stack STK of the microprocessor. The stack STK occupies a non-extendible portion of the RAM delimited by a low address and a high address, which are typically noted in the specifications provided by the manufacturer, for example.
The CPU unit includes various registers, the content of which defines the xe2x80x9ccontextxe2x80x9d of the currently running application program. In particular, this may include: an accumulator register ACCU; a condition codes register CC including various flags such as a flag Z (Zero), flag N (Negative), flag C (Carry), flag H (Half-Carry), flag I (Interrupt Mask), etc; an index register X for the indexed addressing of the memory plane or the addressing of registers; a program counter PC including the address of the currently running instruction, generally including a most significant register PCh and a less significant register PCl; and a stack pointer SP (or stack indexing register) generally including a most significant register SPh and a less significant register SPl, and including the address of the top of the stack STK (i.e., the address of the first free location of the stack).
When the microprocessor switches into the test program while running the application program, the contextual data of the application program is saved in the stack STK to be restored at the end of the test session. A first memory area RZ1 must therefore be reserved in stack STK for saving the context. This area is provided for receiving the current value A0 of the accumulator, the current value CC0 of the condition code register, the current value X0 of the index register, and the most significant bytes PCh0 and the least significant bytes PCl0 of the program counter PC.
On the other hand, when the microprocessor has switched to the test mode, the test program TST-PGR must itself have at its disposal an available area in the stack for the recording of data when running particular instructions. This data may include, for example, two bytes PChT, PClT forming the return value of the program counter PC when running JUMP or CALL instructions. Thus, a second memory area RZ2 must be reserved in the stack STK for recording this data.
Further, the memory space to be reserved in the stack STK of such a microprocessor for providing switching to the test program includes the area RZ1 and the area RZ2. The location of this memory space is not defined and depends on the filling ratio of the stack at the time of switching. In practice, the user that develops an application must make sure that the application program never completely fills the stack, and that at least one free location is left at the top of the stack corresponding to the two above-mentioned areas.
For the user who wishes to best exploit the resources of the microprocessor when developing an application program, the areas RZ1, RZ2 to be reserved in the stack STK is memory space which cannot be used and, consequently, is a waste of the microprocessor""s resources. However, the areas RZ1, RZ2 generally include only a relatively small number of bytes. Thus, the aforementioned problem may become particularly accute when using low cost microprocessors which include limited memory space and a limited size stack. Yet, many of the microprocessors currently in use in the home, automation, and automobile fields are indeed limited size, low cost microprocessors.
It is therefore an object of the present invention to provide a microprocessor that does not require the reservation, in the stack of the microprocessor, of the area RZ2 to be used by the test program.
This and other objects, features, and advantages of the present invention are provided by a microprocessor which may include means for switching into a test program, and means for saving contextual data in a stack of the microprocessor at the time of a switching into the test program. The microprocessor may further include means for delivering on an input/output port of the microprocessor contextual data present in the stack (starting with the top of the stack) at the beginning of a test session, and for decrementing a stack pointer by a value corresponding to the number of delivered contextual data.
More particularly, the microprocessor may include means for further delivering on the input/output port data present in a volatile memory of the microprocessor at the beginning of a test session. Further, the microprocessor may include means for delivering on the input/output port the content of at least one register likely to be modified during a test session at the beginning of a test session.
Additionally, the microprocessor may include means for performing a context restoration command. The context restoration command may include the recovery, via an input/output port, of the contextual data extracted from the stack at the beginning of a test session. It may also include recording this data in the stack and incrementing the stack pointer by a value corresponding to the number of contextual data recovered. Additionally, the means for performing a stack restoration command may also be arranged to recover other data extracted from the microprocessor after switching to the test program, and to record this data at its initial locations.
The present invention also relates to a method of managing the memory space of a microprocessor after switching the microprocessor to a test program and recording contextual data in a stack of the microprocessor. The method may include delivering, on an input/output port of the microprocessor, contextual data present in the stack starting with the top of the stack. Further, this data may be stored in external equipment, and the stack pointer may be decremented by a value corresponding to the number of contextual data delivered at the port.
More particularly, the method may also include delivering on the input/output port and storing in the external equipment data present in a volatile memory of the microprocessor. Further, the method may include delivering on the input/output port and storing in the external equipment the content of at least one register likely to be modified during a test session.
Additionally, the method may include performing context restoration when the microprocessor leaves the test program. The restoration may include recovering, via an input/output port, contextual data extracted from the stack at the time of switching to the test program, recording this data in the stack, and the incrementing the stack pointer by a value corresponding to the number of contextual data recovered. Moreover, the restoration may also include recovering other data extracted from the microprocessor after switching to the test program, and recording this data at initial locations thereof.